package com.demo.xzbd.file;

import java.io.File;

/**
 * File工具类
 * sun 2017-10-27.
 */
public class FileUtils {
    /**
     * 描述：根据文件路径获取项目中的文件
     * @param fileDir 文件路径
     * @return
     * @throws Exception
     */
    public static File getFile(String fileDir) throws Exception{
        String clazzDir = null;
        String fileBaseDir = null;
        File file = null;
        clazzDir = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        fileBaseDir = clazzDir.substring(1,clazzDir.lastIndexOf("classes"));
        file = new File((fileBaseDir + fileDir).replace("/","\\"));
//        file = new File("C:\\workspace_zdemo\\java\\JAVAMANUSCRIPT\\excel_poi\\src\\main\\resources"+fileDir);
        if (!file.exists()) throw new Exception("模版文件不存在");
        return file;
    }
}
